import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';

// 创建评论 API
export const commentApi = createApi({
  reducerPath: 'commentApi',
  baseQuery: fetchBaseQuery({ baseUrl: 'your_base_url' }), // 替换为实际的基础 URL
  endpoints: (builder) => ({
    getComments: builder.query<
      // 这里假设返回类型，你需要根据实际情况修改
      { data: any }, 
      { type: "a" | "c"; source: string; offset?: string | null; limit?: number }>({
      // 显式指定 params 的类型
      query: (params: { type: "a" | "c"; source: string; offset?: string | null; limit?: number }) => ({ url: "/comments", params })
    }),
    getComment: builder.mutation({
      query: (params) => ({
        url: 'comments',
        method: 'POST',
        body: params,
      }),
    }),
  }),
});

export const { useGetCommentsQuery } = commentApi;
export const { useGetCommentMutation: useRequestCommentsMutation } = commentApi